<template>
	<view class="wrap">
		<u-form :model="dataForm" ref="uForm">
			<u-form-item label-position="left" label="上传图片证据:" prop="imgUrl" label-width="30%">
				<u-upload width="160" height="160" :action="uploadUrl" :header="headers" :fileList="fileList"
					@on-success="success" @on-remove="uploadDelete" :deletable="true" max-count="3">
				</u-upload>
			</u-form-item>
			<u-form-item label-position="left" label="选择举报原因:" prop="type" label-width="30%">
				<u-radio-group v-model="dataForm.reportType" slot="right">
					<u-radio v-for="(item, index) in reportTypeList" :key="index" :name="item.value">
						{{ item.name }}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label-position="left" label="填写举报内容:" prop="intro" label-width="30%">
				<u-input type="textarea" :border="true" placeholder="请输入丢失宠物相关描述...:" v-model="dataForm.reportContent" />
			</u-form-item>
		</u-form>
		<u-button @click="submit" type="primary">提交</u-button>
	</view>
</template>

<script>
	import {
		submitPetreport
	} from '@/api/report/report.js'
	export default {
		data() {
			return {
				uploadUrl: 'http://127.0.0.1:8181/pet-system/piclocal/upload/pic',
				headers: {
					token: uni.getStorageSync('token')
				},
				fileList: [],
				dataForm: {
					reportedUserId: '',
					reportType: 0,
					reportContent: '',
					imageUrl: '',
					imageUrlList: []
				},
				reportTypeList: [{
						name: '淫秽信息',
						value: 0,
						disabled: false
					},
					{
						name: '诈骗信息',
						value: 1,
						disabled: false
					},
					{
						name: '广告信息',
						value: 2,
						disabled: false
					},
					{
						name: '其他',
						value: 3,
						disabled: false
					}
				]
			}
		},
		onLoad(e) {
			console.log(e.creator)
			this.dataForm.reportedUserId = e.creator
		},
		methods: {
			success(data, index, lists, name) {
				this.dataForm.imageUrlList.push(data.data.imgAddress)
				this.dataForm.imageUrl = this.dataForm.imageUrlList.join(",")
				console.log(this.dataForm.imageUrl)
			},
			// 图标删除回调函数
			uploadDelete(index, lists, name) {
				console.log(index)
				this.dataForm.imageUrlList.splice(index, 1)
				this.dataForm.imageUrl = this.dataForm.imageUrlList.join(",")
				console.log(this.dataForm.imageUrl)
			},
			submit() {
				console.log(this.dataForm)
				submitPetreport(this.dataForm).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '已成功提交！',
							icon: 'success'
						});
						this.dataForm = {}
						this.fileList = []
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}
</style>